<%@ page language="java" pageEncoding="UTF-8"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.HashSet"%>
<%@page import="java.util.Set"%>
<%@page import="com.shsh.safemanage.util.Constants"%>
<%@page import="com.shsh.safemanage.dao.DaoCreator"%>
<%@page import="com.shsh.safemanage.dao.DepartmentDao"%>
<%@page import="com.shsh.safemanage.model.Department1"%>
<%@page import="java.util.List"%>

<%
{
	DepartmentDao departmentDao = DaoCreator.createDepartmentDao();
	List<Department1> depart1List = new ArrayList<Department1>();
	List<Department1> shiyebuList = departmentDao.getDepartment1List(Constants.DEPARTMENT_TYPE_SHIYEBU);
	List<Department1> chushiList = departmentDao.getDepartment1List(Constants.DEPARTMENT_TYPE_JIGUAN);
	depart1List.addAll(shiyebuList);
	depart1List.addAll(chushiList);
	
	List<Department1> selectedDepart1List = (List<Department1>) session.getAttribute(Constants.SESSION_PROBLEM_DEPARTMENT1);
	Set<Long> selectedIDSet = new HashSet<Long>();
	if (selectedDepart1List != null) {
		for (Department1 selectedDepart1 : selectedDepart1List) {
			selectedIDSet.add(selectedDepart1.getId());
		}
	}
	
	for (int i = 0; i < depart1List.size(); i++) {
		Department1 depart1 = depart1List.get(i);
		if (depart1.getId().equals(Constants.DEPARTMENT1_ID_FUZONGSHI)
				|| depart1.getId().equals(Constants.DEPARTMENT1_ID_LINGDAOBANZI)) {
			depart1List.remove(i--);
		}
	}
%>
<table width="680" border="1" cellpadding="0"
		cellspacing="0">
	<%
	boolean isBreak = false;
	for (int i = 0; i < 100; i++) {
		if (isBreak) {
			break;
		}
	%>
	<tr>
		<%
		for (int j = 0; j < 4; j++) {
			int index = i * 4 + j;
			if (index >= depart1List.size()) {
				isBreak = true;
				break;
			}
			Department1 depart1 = depart1List.get(index);
		%>
		<td width="25%">
		<table width="100%">
			<tr>
				<td width="20%" align="right">
				<input type="checkbox" name="depart1IDCheckbox" style="margin-left: 8px" 
					value="<%=depart1.getId()%>" <%=(selectedIDSet.contains(depart1.getId()))? "checked":"" %> />
				</td>
				<td align="left"><%=depart1.getDepartmentName()%></td>
			</tr>
		</table>
		</td>
		<%
		}
		%>
	</tr>
	<%
	}
	%>
</table>
<input type="button" value="确 定" onclick="chooseDepartment1List()" style="margin-top: 5px" />
<input type="button" value="取 消" onclick="closeWaitingDialog('escalateUserDialog')" style="margin-top: 5px" />

<script type="text/javascript">
function chooseDepartment1List() {
	var checkElements = document.getElementsByName('depart1IDCheckbox');
	var depart1IDList = '';
	for (var i = 0; i != checkElements.length; i++) {
		var checkElement = checkElements[i];
		if (checkElement.checked) {
			if (depart1IDList == '') {
				depart1IDList = depart1IDList + checkElement.value;
			} else {
				depart1IDList = depart1IDList + ',' + checkElement.value;
			}
		}
	}
	
	if (depart1IDList == '') {
		$.dialog.alert('请选择协助的事业部和科室');
	}
	
	$.ajax({
		type:'post',
		url:'choose_problem_depart1list_process.jsp',
		data:{
			id: depart1IDList
		},
		success:function(data,state,xmlhttp){
			var obj = null;
			try {
				obj = eval('(' + data + ')');
			} catch (e) {
			}
			if (typeof(obj.isSuccess) != 'undefined') {
				if (obj.isSuccess == 'true') {
					closeWaitingDialog('escalateUserDialog');
					loadPageSection('<%=request.getContextPath()%>/feedback_process_method.jsp', 'feedbackProcessMethodDiv', {}, false,
						function() {
							var processRadio3 = document.getElementById('processRadio3');
							if (processRadio3 != null) {
								processRadio3.checked = true;
							}
							chooseProcessMethod(3);
							
							var processRadio5 = document.getElementById('processRadio5');
							if (processRadio5 != null) {
								processRadio5.checked = true;
							}
							chooseProcessMethod(5);
						});
				} else {
					$.dialog.alert(obj.error);
				}
			}
		}
	});
}
</script>
<%
}
%>